import { createParamDecorator, ExecutionContext } from '@nestjs/common';
import { AuthDocument } from 'src/system-user/schemas/auth.schema';
import { SystemUserDocument } from 'src/system-user/schemas/system-user.schema';

export interface SystemUserDecoratorType
  extends Omit<SystemUserDocument, 'auth'> {
  auth: AuthDocument;
  ip: string;
}

export const OperUser = createParamDecorator(
  (data: unknown, ctx: ExecutionContext): SystemUserDecoratorType => {
    const request = ctx.switchToHttp().getRequest();
    return request?.userInfo ? request.userInfo : null;
  },
);
